

layui.config({
	version: '1510164124181'
}).use(['form', 'laydate', 'laypage', 'layer', 'element'], function () {
	form = layui.form;
	layer = layui.layer;
	laydate = layui.laydate;//日期
	laypage = layui.laypage;//分页
	element = layui.element; //元素操作
	inituserdata();
});
function SearchInfo() {
	pageNo = 1;
	inituserdata();
}
function onloadInfo (){
	SearchInfo()
}
function inituserdata() {
	var typeid = $("#CarouseList option:selected").val();
	$.ajax({
		type: "GET",
		url: httpurl + "/carouselist",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType: 'application/json',
		data: {
			"page": pageNo,
			"pagesize": pageRecords,
			"typeid": typeid
		},
		success: function (data) {
			layer.closeAll();
			totalRecords = data.data.total;
			var dataList = data.data.list;
			var info = "";
			if (dataList.length > 0) {
				for (var i = 0; i < dataList.length; i++) {
					let typeTitle = getTypeTitle(dataList[i].type)
					info += '<tr>' +
						'<td><input type="checkbox"  name="box" class="aceChild"/></td>' +
						'<td><img class="carouseimage" src="' + visitimgurl + "/" + dataList[i].picurl + '"/></td>' +
						'<td>' + typeTitle + '</td>' +
						'<td>' + dataList[i].sort + '</td>' +
						'<td><a href="AddCarouse.html?carouseid=' + dataList[i].id + '">编辑</a>&nbsp;&nbsp;<a href="#" data-info="DeleteAdvertInfo" onclick="DeleteInfo(this);" data-id="' + dataList[i].id + '">删除</a></td>' +
						'</tr>';
				}
			} else {
				dataHtml += '<tr>'
					+ '<td colspan="12" style="text-align:center;">暂无数据</td>'
					+ '</tr>';
			}
			$("#tableInfo tbody").html(info);
			page();
		}
	});
}

//分页
function page() {
	laypage.render({
		elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
		, count: totalRecords //数据总数，从服务端得到
		, curr: pageNo //获取起始页 location.hash.replace('#!fenye=', '')
		, hash: 'fenye' //自定义hash值
		, layout: ['count', 'prev', 'page', 'next', 'skip']
		, limit: pageRecords
		, jump: function (obj, first) {
			//首次不执行
			if (!first) {
				pageNo = obj.curr;// 当前页数;
				pageRecords = obj.limit;// 当前页面记录数
				inituserdata();
			}
		}
	});
}

function getTypeTitle(type) {
	let typeTitle = ''
	switch (type) {
		case 1:
			typeTitle = '首页轮播图'
			break;
		case 2:
			typeTitle = '导航分类'
			break;
		case 3:
			typeTitle = '天兰头条轮播'
			break;
		case 4:
			typeTitle = '活动专场入口'
			break;
		case 5:
			typeTitle = '秒杀活动'
			break;
		case 6:
			typeTitle = '拼单活动'
			break;
		case 7:
			typeTitle = '限时特惠'
			break;
		case 9:
			typeTitle = '首页banner图'
			break;
		case 10:
			typeTitle = '商品分类'
			break;
		case 11:
			typeTitle = '积分商城'
			break;
		case 12:
			typeTitle = '领券中心'
			break;
		case 13:
			typeTitle = '个人中心'
			break;
		default:
			typeTitle = '未知'
			break;
	}
	return typeTitle
}
